<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        header a{
            text-decoration: none;
            color: #6c6c6c;
        }
        .el-table .el-table__cell{
            padding: 0;
        }
        .el-table .cell{
            white-space: nowrap;/*设置内容不换行*/
            text-overflow: ellipsis;
        }
        .p_img:hover{
            position: relative;
            top: 5px;
            box-shadow: 0 0 10px 5px #333;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="110px" style="padding: 0">
            <div style="min-width: 1800px;margin: 0 auto">
                <el-row :gutter="20">
                    <el-col :span="12"><div class="grid-content bg-purple"><a href="/"><img src="images/stumalllogo.png"></a></div></el-col>
                    <el-col :span="12" ><div class="grid-content bg-purple" >
                        <div class="line"></div>
                        <el-menu
                                :default-active="activeIndex2"
                                class="el-menu-demo"
                                mode="horizontal"
                                @select="handleSelect2"
                                text-color="#f"
                                >
                            <el-menu-item index="1"class="el-icon-star-on">收藏</el-menu-item>
                            <el-menu-item index="2"class="el-icon-s-order">订单1</el-menu-item>
                            <el-menu-item index="3"class="el-icon-shopping-cart-full">购物车1</el-menu-item>
                            <el-submenu index="4">
                                <template slot="title" class="el-icon-s-tools">管理</template>
                                <el-menu-item index="4-1"class="el-icon-s-operation">修改密码</el-menu-item>
                                <el-menu-item index="4-2"class="el-icon-user-solid">个人资料</el-menu-item>
                                <el-menu-item index="4-3"class="el-icon-picture">上传头像</el-menu-item>
                                <el-menu-item index="4-4"class="el-icon-s-home">收货管理</el-menu-item>
                            </el-submenu>
                            <el-menu-item index="5"class="el-icon-s-custom"     v-if="user==''">登录</el-menu-item>
                            <el-menu-item index="6"class="el-icon-edit-outline" v-if="user==''">注册</el-menu-item>
                            <el-menu-item index="7"class="el-icon-sunny" v-if="user!=''">欢迎回来</el-menu-item>
                            <el-menu-item index="8"class="el-icon-switch-button" v-if="user!=''">退出登录</el-menu-item>
                        </el-menu>
                    </div></el-col>
                </el-row>

            </div>
            <!--导航菜单开始-->
            <div style="background-color: #82c8ec;" >
                <el-menu style="width: 1200px;margin: 0 auto"
                    :default-active="activeIndex"
                    class="el-menu-demo"
                    mode="horizontal"

                    background-color="#82c8ec"
                    text-color="#fff"
                    active-text-color="#fff" >
                <el-menu-item   v-for="a in activityArr" :index="a.id"><a :href="a.url">{{a.name}}</a></el-menu-item>
                    <div style="float: right;position: relative;top: 10px">
                        <el-input placeholder="请输入搜索内容" v-model="wd">
                            <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
                        </el-input>
                    </div>
            </el-menu>
            </div>
            <!--导航菜单结束-->

        </el-header>
        <el-main style="width: 1200px;margin: 0 auto">
            <el-row gutter="20">
                <el-col span="4">
                <el-card style="border-radius: 4px;background-color: white;height: 300px;">
                <ul style="list-style:none;margin: 0 auto">
                    <li v-for="a in categoryArr"> <el-link  :href="'/123?id='+a.id">{{a.name}}</el-link></li>
                </ul>
                </el-card>


                </el-col>
                <el-col span="20">
                    <!--轮播图开始-->
                    <el-carousel height="300px">
                        <el-carousel-item v-for="b in bannerArr">
                            <img :src="b.url" width="100%" height="100%" alt="">
                        </el-carousel-item>

                    </el-carousel>
                    <!--轮播图结束-->
                </el-col>
            </el-row>
              <!--    新到好货排行榜      -->
            <el-row gutter="10">
            <el-col span="12">
                <el-card>
                    <h3>
                        <i style="font-weight: bold" class="el-icon-s-shop">新到好货</i>
                    </h3>
                    <div v-for="a in newProductArr">
                        <el-row :gutter="20">
                            <el-col :span="10"><div class="grid-content bg-purple"> <el-link type="primary" :href="'/123?id='+a.id">{{a.title}}</el-link></div></el-col>
                            <el-col :span="10"><div class="grid-content bg-purple"><span > ￥{{a.price}} </span></div></el-col>
                            <el-col :span="4"><div class="grid-content bg-purple"><img :src="a.url"  height="40px" width="50px"></div></el-col>
                        </el-row>
                        <el-divider></el-divider>
                    </div>
                </el-card>
            </el-col>
            <!--    热销排行榜      -->
            <el-col span="12">
                <el-card>
                    <h3>
                        <i style="font-weight: bold" class="el-icon-trophy">热销排行</i>
                    </h3>
                    <div v-for="a in hotProductArr">
                        <el-row :gutter="20">
                            <el-col :span="10"><div class="grid-content bg-purple"><el-link type="primary" :href="'/123?id='+a.id">{{a.title}}</el-link></div></el-col>
                            <el-col :span="10"><div class="grid-content bg-purple"><span > ￥{{a.price}} </span></div></el-col>
                            <el-col :span="4"><div class="grid-content bg-purple"><img :src="a.url"  height="40px" width="50px"></div></el-col>
                        </el-row>
                        <el-divider></el-divider>
                    </div>
                </el-card>
            </el-col>
            </el-row>
            <h1 style="background-color: #5bc0de;text-align:center;color: #303133"><i class="el-icon-present"></i>为你推荐<i class="el-icon-present"></i></h1>
        <!--商品列表开始-->
            <el-row gutter="20" >
                <el-col style="margin: 10px 0" span="6" v-for="p in productArr" >
                    <el-card >
                        <a :href="'/detail.html?id='+p.id" style="text-decoration: none;color:#3f3f3f;">
                        <img class="p_img" :src="p.url" width="200px" height="200px" alt="">
                        </a>
                        <div>
                            <p style="font-size: 15px;height: 40px;margin-top: 0">
                                <a :href="'/detail.html?id='+p.id" style="text-decoration: none;color:#3f3f3f;">
                                {{p.title}}
                                </a>
                            </p>
                            <p style="font-size: 12px;color: #666">
                                ￥{{p.price}} 浏览量{{p.viewCount}}
                                <span style="float: right">销量:{{p.saleCount}}件</span>
                            </p>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
            <el-row style="text-align:center;">
                <el-button type="primary" round v-if="load==1" @click="loadding()">加载更多</el-button>
                <el-button type="primary" round v-if="all" >到底了</el-button>
                <el-button type="primary" :loading="true" v-if="load==2">加载中</el-button>
            </el-row>
        <!--商品列表结束-->
        </el-main>
        <el-footer>
            <div style="height: 95px;background-image: url('images/wave.png')">
            </div>
            <div style="background-color: #3f3f3f;padding:30px 0;text-align: center;color: #b1b1b1">
                页脚
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                all:false,
                index:0,
                load: 1,
                user: {},
                hotProductArr:[],
                newProductArr:[],
                activityArr:[],
                categoryArr:[],
                bannerArr:[],
                activeIndex:"",
                activeIndex2: '',
                wd:"",
                topArr:[],
                productArr:[],
                productArr2:[]
            }
        },
       methods: {
           handleSelect(key,keyPath){
               console.log(key,keyPath);
               location.href="/result.html?id="+key;
           },
           search(){
               location.href="/result.html?wd="+v.wd;
           },
           handleSelect2(key, keyPath) {
               console.log(key, keyPath);
               if(key==1){
                   location.href="/favorites.html";
               }else if(key==2){
                   location.href="orders.html";
               }else if(key==3){
                   location.href="cart.html";
               }else if(key=='4-1'){
                   location.href="/login1.html";
               }else if(key=='4-2'){
                   location.href="";
               }else if(key=='4-3'){
                   location.href="";
               }else if(key=='4-4'){
                   location.href="";
               }else if(key==5){
                   location.href="/login.html";
               }else if(key==6){
                   location.href="/reg.html";
               }else if(key==7){

               }else if(key==8){
                   axios.get("/logout").then(function (response){
                       v.$message.success("退出成功");
                       v.user='';
                   })
               }
           },
           categoryClick(id){
                  console.log(id);
           },
           handleOpen(key, keyPath) {
               console.log(key, keyPath);
           },
           handleClose(key, keyPath) {
               console.log(key, keyPath);
           },
           loadding(){
               v.load=2;
               v.index=v.index+1;
               axios.get("product/loadding/index?id="+v.index).then(function (response){
                   v.productArr2 = response.data;
                   if(v.productArr2==''){
                       v.load = 3;
                       v.all=true;
                       return;
                   }
                   v.productArr= v.productArr.concat(v.productArr2);
                   v.load=1;
               })
           }

       },
       created:function (){
        axios.get("category/select").then(function (response){
            v.categoryArr = response.data;
        })
        axios.get("/banner/select").then(function (response){
               v.bannerArr = response.data;
        })
        axios.get("/product/select/top").then(function (response){
               v.topArr = response.data;
        })
        axios.get("/product/select/index").then(function (response){
              v.productArr = response.data;
        })
        axios.get("/product/hotProduct/index").then(function (response){
               v.hotProductArr = response.data;
        })
        axios.get("/product/newProduct/index").then(function (response){
               v.newProductArr = response.data;
        })
        axios.get("/activity").then(function (response){
               v.activityArr = response.data;
        })
        axios.get("/getUser").then(function (response){
               v.user = response.data;
        })

       }

   })
</script>
</html>
